using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_ProductInStock : Member, IRequiresSessionState
{
	protected TextBox TxtProductName;
	protected DropDownList ProductType;
	protected Button Button1;
	protected GridView GridView1;
	protected Button OnSale_Button;
	protected Button btn_editProducts;
	protected Button Delete_Button;
	protected ObjectDataSource ObjectDataSource1;
	private int UserID = 0;
	private string wherestr = "";
	private string orderstr = " order by ProductID Desc";
	private ArrayList al = new ArrayList();
	private IDbDataParameter[] param = null;
	private Pagination _pageHand = null;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected Pagination pageHand
	{
		get
		{
			Pagination pageHand;
			if (this._pageHand == null)
			{
				this._pageHand = new Pagination();
				this._pageHand.SQL_CloseTablePre = false;
				this._pageHand.SQL_Fields = "*,(Select ClassName From [HLShop_Class] Where ClassID=HLShop_Product.ClassID) as ClassName";
				this._pageHand.P_Object = Language.GetAdminMsg("Product/ProductName");
				pageHand = this._pageHand;
			}
			else
			{
				pageHand = this._pageHand;
			}
			return pageHand;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		if (!base.IsPostBack)
		{
			this.BindList();
		}
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.GridView1_PageIndexChanging);
	}
	private void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindList();
	}
	protected void BindList()
	{
		this.QuestString();
		Shop_Product shop_Product = new Shop_Product(this.conn);
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		if (this.param == null)
		{
			this.GridView1.DataSource = shop_Product.GetInStockBySalerID(this.UserID, this.wherestr, this.orderstr, null);
		}
		else
		{
			this.GridView1.DataSource = shop_Product.GetInStockBySalerID(this.UserID, this.wherestr, this.orderstr, this.param);
		}
		this.GridView1.DataBind();
	}
	protected void QuestString()
	{
		this.wherestr += "and IsDeleted=0  ";
		string text = this.TxtProductName.Text;
		if (text != string.Empty)
		{
			this.wherestr += "and ProductName like '%' + @ProductName + '%' ";
			this.al.Add(this.conn.CreateParameter("@ProductName", DbType.String, text.Trim()));
		}
		if (this.ProductType.SelectedValue != "" && this.ProductType.SelectedValue != "0")
		{
			this.wherestr = this.wherestr + "and ProductType=" + this.ProductType.SelectedValue + " ";
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "Where");
		}
	}
	protected void Search_OnClick(object sender, EventArgs e)
	{
		this.BindList();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void StockPorityButton_Command(object sender, CommandEventArgs e)
	{
		ArrayList arrayList = new ArrayList();
		string text = Text.CheckNumList(Fetch.GetOrPost("productids"));
		string[] array = text.Split(new char[]
		{
			','
		});
		if (text != "")
		{
			if (e.CommandName == "OnSale")
			{
				for (int i = 0; i < array.Length; i++)
				{
					DataSet dataSet = this.conn.GetDataSet("select * from HLShop_Product where ProductID=" + int.Parse(array[i]));
					if (dataSet.Tables[0].Rows[0]["ProductType"].ToString() == "2")
					{
						this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('" + dataSet.Tables[0].Rows[0]["ProductName"].ToString() + " 属于拍卖成功商品,如果想继续拍卖请删除再重新发布！');</script>");
						return;
					}
					if (int.Parse(dataSet.Tables[0].Rows[0]["Stocks"].ToString()) <= 0)
					{
						this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('" + dataSet.Tables[0].Rows[0]["ProductName"].ToString() + " 的数量为0，无法上架！');</script>");
						return;
					}
					dataSet.Dispose();
				}
			}
			if (e.CommandName == "Delete")
			{
				int num = 0;
				for (int j = 0; j < array.Length; j++)
				{
					string sql = "update HLShop_Product set IsDeleted=1 where ProductID=" + array[j];
					num = this.conn.Execute(sql);
				}
				if (num > 0)
				{
					this.WriteErrMsg("", "批量信息删除成功！", "Shop_ProductInStock.aspx");
				}
			}
			Shop_Product shop_Product = new Shop_Product(this.conn);
			if (e.CommandName != "Delete")
			{
				int num2 = 0;
				for (int i = 0; i < array.Length; i++)
				{
					num2 = shop_Product.EditSaleProductProtity(array[i], e.CommandName.ToString());
				}
				if (num2 < 0)
				{
					this.WriteErrMsg("", "操作失败!", "");
					return;
				}
			}
			this.BindList();
		}
		else
		{
			this.BindList();
		}
	}
	protected void btn_editProducts_Click(object sender, EventArgs e)
	{
		string text = Text.CheckNumList(Fetch.GetOrPost("productids"));
		if (text == "")
		{
			this.WriteErrMsg("", "未选中编辑项", "");
		}
		else
		{
			base.Response.Redirect("EditProducts.aspx?tag=EnableSale&productIDS=" + text);
		}
	}
}
